//状态变量
let v = null;
function useState(initValue){
  //第一次执行对状态进行赋值
  if(v === null){
    v = initValue;
  }

  //声明一个函数
  function setV(newV){
    //判断 newV 的类型
    if(typeof newV === 'function'){
      //调用函数 获取函数的返回值
      let result = newV(v);
      //更新状态值
      v = result;
    }else{
      v = newV;
    }
  }

  return [v, setV]
}

//代码示例
{
  let [count, setCount] = useState(100);
  setCount(101);
}

{
  let [count, setCount] = useState(100);
  setCount(120);
}

{
  let [count, setCount] = useState(100);
  setCount(130);
  setCount(value => {
    // console.log(value);
    return value + 10;
  });
}

{
  let [count, setCount] = useState(100);
  console.log(count);
}
